from selenium import webdriver
import time #导入time类
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select


driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://www.baidu.com')
setting=driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(setting).perform()
time.sleep(4)
driver.find_element_by_link_text("搜索设置").click()
time.sleep(3)
driver.find_element_by_class_name("prefpanelgo").click()
time.sleep(2)
# 延迟2秒
driver.switch_to.alert.accept()
#通过switch_to.alert.accept()来接受警告框,相当于点击警告框的确认按钮

driver.switch_to_alert.dismiss()
#相当于点击来取消警告框.
driver.quit()